package org.niit.spark

import org.apache.spark.rdd.JdbcRDD
import org.apache.spark.{SparkConf, SparkContext}

import java.sql.DriverManager

object  JDBCMysql {
  def main(args: Array[String]): Unit = {
    val conf=new SparkConf().setAppName("mysql").setMaster("local[*]")
    val sc=new SparkContext(conf)
    sc.setLogLevel("error")
    val  connec=() => DriverManager.getConnection("jdbc:mysql://123.56.187.176:1101/edu_report?characterEncoding=UTF-8","niit","123456")
    val mysqlRdd=new JdbcRDD(sc, connec, "select * from ads_complete_complete_chapter_count_per_course where recent_days > ? or recent_days < ?",
      1, 40, 1,
      x => {
        val dt = x.getInt(1)
        val recent_days = x.getInt(2)
        (dt, recent_days)

      })

    mysqlRdd.collect().foreach(println(_))

  }

}
